<%@ page language="java" pageEncoding="UTF-8" %>
<%@ include file="../portal_common/taglibs.jsp" %>
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"/>
    <title>设置-个人信息</title>
    <link rel="icon" href="/assets/img/favicon.ico">

    <link rel="stylesheet" type="text/css" href="${ctx}/css/webbase.css"/>
    <link rel="stylesheet" type="text/css" href="${ctx}/css/pages-seckillOrder.css"/>
</head>

<body>
<!-- 头部栏位 -->
<!--页面顶部-->
<div id="nav-bottom">
    <!--顶部-->
    <%@include file="../portal_common/top.jsp" %>
</div>

<script type="text/javascript" src="${ctx}/js/plugins/jquery/jquery.min.js"></script>
<script type="text/javascript">
    $(function () {
        $("#service").hover(function () {
            $(".service").show();
        }, function () {
            $(".service").hide();
        });
        $("#shopcar").hover(function () {
            $("#shopcarlist").show();
        }, function () {
            $("#shopcarlist").hide();
        });

    })

</script>
<script type="text/javascript" src="${ctx}/js/plugins/jquery.easing/jquery.easing.min.js"></script>
<script type="text/javascript" src="${ctx}/js/plugins/sui/sui.min.js"></script>
<script type="text/javascript" src="${ctx}/js/plugins/jquery-placeholder/jquery.placeholder.min.js"></script>
<script type="text/javascript" src="${ctx}/js/widget/nav.js"></script>
<script type="text/javascript" src="${ctx}/js/plugins/birthday/birthday.js"></script>
<script type="text/javascript" src="${ctx}/js/plugins/citypicker/distpicker.data.js"></script>
<script type="text/javascript" src="${ctx}/js/plugins/citypicker/distpicker.js"></script>
<script type="text/javascript" src="${ctx}/js/plugins/upload/uploadPreview.js"></script>
<script type="text/javascript" src="${ctx}/js/pages/main.js"></script>
<script>
    $(function () {
        $.ms_DatePicker({
            YearSelector: "#select_year2",
            MonthSelector: "#select_month2",
            DaySelector: "#select_day2"
        });
    });
</script>
</body>
<!--header-->
<div id="account">
    <div class="py-container">
        <div class="yui3-g home">
            <!--左侧列表-->
            <div class="yui3-u-1-6 list">

                <div class="person-info">
                    <div class="person-photo">
                        <c:if test="${tbUser.headPic == null}">
                            <img src="${ctx}/img/_/photo.png" alt="">
                        </c:if>
                        <c:if test="${tbUser.headPic != null}">
                            <img width="60px" height="60px" src="${tbUser.headPic}" alt="">
                        </c:if>
                    </div>
                    <div class="person-account">
                        <span class="name">${username}</span>
                    </div>
                    <div class="clearfix"></div>
                </div>
                <div class="list-items">
                    <dl>
                        <dt><i>·</i> 订单中心</dt>
                        <dd><a href="${ctx}/order/list">我的订单</a></dd>
                        <dd><a href="${ctx}/order/list?status=1">待付款</a></dd>
                        <dd><a href="${ctx}/order/list?status=3">待发货</a></dd>
                        <dd><a href="${ctx}/order/list?status=4">待收货</a></dd>
                        <dd><a href="${ctx}/order/list?status=6">待评价</a></dd>
                        <dd><a href="${ctx}/order/list?status=2">交易关闭</a></dd>
                    </dl>
                    <dl>
                        <dt><i>·</i> 设置</dt>
                        <dd><a href="${ctx}/user/details" class="list-active">个人信息</a></dd>
                        <dd><a href="${ctx}/address/list">地址管理</a></dd>
                    </dl>
                </div>
            </div>
            <!--右侧主内容-->
            <div class="yui3-u-5-6">
                <div class="body userInfo">
                    <ul class="sui-nav nav-tabs nav-large nav-primary ">
                        <li class="active"><a href="#one" data-toggle="tab">基本资料</a></li>
                        <li><a href="#two" data-toggle="tab">头像照片</a></li>
                        <li><a href="#three" data-toggle="tab">修改密码</a></li>
                    </ul>
                    <div class="tab-content ">
                        <div id="one" class="tab-pane active">
                            <form id="form-msg" class="sui-form form-horizontal">
                                <div class="control-group">
                                    <label for="nickName" class="control-label">昵称：</label>
                                    <div class="controls">
                                        <input type="text" id="nickName" value="${tbUser.nickName}" name="nickName"
                                               placeholder="昵称">
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label for="name" class="control-label">真实姓名：</label>
                                    <div class="controls">
                                        <input type="text" id="name" value="${tbUser.name}" name="name"
                                               placeholder="真实姓名">
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label for="email" class="control-label">邮箱：</label>
                                    <div class="controls">
                                        <input type="text" id="email" value="${tbUser.email}" name="email"
                                               placeholder="邮箱">
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label for="phone" class="control-label">手机：</label>
                                    <div class="controls">
                                        <input type="text" id="phone" value="${tbUser.phone}" name="phone"
                                               placeholder="手机">
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label">性别：</label>
                                    <div class="controls">
                                        <select id="sex">
                                            <option value="1">男</option>
                                            <option value="2">女</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label">生日：</label>
                                    <div class="controls">
                                        <input type="text" name="birthday" id="birthday"
                                               value="<fmt:formatDate value="${tbUser.birthday}" pattern="yyyy-MM-dd"/>"
                                               placeholder="2000-01-23">
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label"></label>
                                    <div class="controls">
                                        <button type="button" id="dataPerfect1" class="sui-btn btn-primary">立即完善</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                        <div id="two" class="tab-pane">
                            <div class="new-photo">
                                <p>当前头像：</p>
                                <div class="upload">
                                    <c:if test="${tbUser.headPic == null}">
                                        <img id="imgShow_WU_FILE_0" width="100px" height="100px"
                                             src="${ctx}/img/_/photo_icon.png" alt="">
                                    </c:if>
                                    <c:if test="${tbUser.headPic != null}">
                                        <img id="imgShow_WU_FILE_0" width="100px" height="100px"
                                             src="${tbUser.headPic}" alt="">
                                    </c:if>
                                    <input type="file" id="up_img_WU_FILE_0" onchange="headPic()"/>
                                    <button onclick="headPic()">上传</button>
                                </div>
                            </div>
                        </div>
                        <div id="three" class="tab-pane">
                            <form class="sui-form form-horizontal sui-validate" id="jsForm">
                                <div class="control-group">
                                    <label class="control-label">密码：</label>
                                    <div class="controls">
                                        <input class="fn-tinput" type="text" name="password"
                                               placeholder="新密码" required id="password" data-rule-remote="php.php">
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label"></label>
                                    <div class="controls">
                                        <button type="button" id="rePassword" class="sui-btn btn-primary">提交</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>
<script>
    function headPic() {
        // var file = $('#up_img_WU_FILE_0').file;
        // console.log(file)
        var files = document.getElementById("up_img_WU_FILE_0").files;
        console.log(files);
        var formdata = new FormData();
        formdata.append("file", files[0]);
        $.ajax({
            url: "${ctx}/upload/image",
            type: "post",
            data: formdata,
            contentType: false, //- 必须false才会自动加上正确的Content-Type
            processData: false, //- 必须false才会避开jQuery对 formdata 的默认处理,XMLHttpRequest会对 formdata 进行正确的处理
            success: function (res) {
                console.log(res);
                if (res.success) {
                    var headPic = 'http://localhost:8081/image/' + res.message;
                    $.ajax({
                            url: "${ctx}/user/update",
                            type: 'post',
                            data: {
                                'headPic': headPic,
                                'id':${tbUser.id}
                            },
                            dataType: 'json',
                            success: function (response) {
                                console.log(response);
                                if (response.success) {
                                    alert(response.message);
                                    window.location.reload();
                                } else {
                                    alert(response.message);
                                }
                            }
                        }
                    );
                } else {
                    alert(res.message)
                }
            }
        });
    }

    $("#rePassword").click(function () {
        var val = $('#password').val();
        console.log(val);
        if (val.length < 6 || val.length > 12) {
            alert('密码长度6-12位');
            return;
        }
        $.ajax({
                url: "${ctx}/user/repassword",
                type: 'post',
                data: {
                    'password': val,
                    'id':${tbUser.id}
                },
                dataType: 'json',
                success: function (response) {
                    console.log(response);
                    if (response.success) {
                        alert(response.message);
                        window.location.reload();
                    } else {
                        alert(response.message);
                    }
                }
            }
        );
    });

    $('#dataPerfect1').click(function () {
        var nickName = $('#nickName').val();
        var name = $('#name').val();
        var phone = $('#phone').val();
        var email = $('#email').val();
        var sex = $('#sex').val();
        var birthday = $('#birthday').val();
        $.ajax({
                url: "${ctx}/user/update",
                type: 'post',
                data: {
                    'nickName': nickName,
                    'name': name,
                    'phone': phone,
                    'email': email,
                    'sex': sex,
                    'birthday': birthday,
                    'id':${tbUser.id}
                },
                dataType: 'json',
                success: function (response) {
                    console.log(response);
                    if (response.success) {
                        alert(response.message);
                        window.location.reload();
                    } else {
                        alert(response.message);
                    }
                }
            }
        );
    })
</script>
<!-- 底部栏位 -->
<!--页面底部-->
<%@include file="../portal_common/foot.jsp" %>
<!--页面底部END-->

</html>